package it.polimi.loganalyzer.model.mapper;

import it.polimi.loganalyzer.model.State;

import java.util.HashMap;
import java.util.regex.Pattern;

public class DefaultMapper implements Mapper{
	
	private HashMap<Pattern, State> mapping;
	
	public DefaultMapper(){
		this.mapping = new HashMap<Pattern, State>();

	}
	
	public  void registerStateExpression(String regEx, State state){
		this.mapping.put(Pattern.compile(regEx), state);
	}
	
	public State matches(String url) {
		for(Pattern pattern : mapping.keySet()){
			if(pattern.matcher(url).find())
				return mapping.get(pattern);
		}
		return null;
	}
}
